 /*
 * ComerciosBusquedaFrame.java
 *
 * Created on 16 de abril de 2008, 11:45 PM
 */
package org.contabilidad.informes;

import org.mybeans.Sesion;

import org.mybeans.CodigosRecargoBeans;
import org.mybeans.ContribuyentesBeans;
import org.mybeans.ComerciosBeans;
import org.mybeans.VehiculosBeans;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author  avbravo
 */
public class ContabilidadInformeIngresoGeneralesFrame extends javax.swing.JFrame {

    Sesion sesion;
    int fila = -1;
    DefaultTableModel modelo;
    VehiculosBeans vehiculosBeans;
    ContribuyentesBeans contribuyentesBeans;
    ComerciosBeans comerciosBeans;
    private int NumeroRegistrosSubGrupo = -1;
    private int NumeroRegistrosGrupo = -1;
    List<String> ListaIdSubGrupo = new ArrayList<String>();
    List<Double> ListaTotalSubGrupo = new ArrayList<Double>();
    List<String> ListaIdGrupo = new ArrayList<String>();
    List<Double> ListaTotalGrupo = new ArrayList<Double>();

    /** Creates new form ComerciosBusquedaFrame */
    public ContabilidadInformeIngresoGeneralesFrame() {
        initComponents();
        sesion = new Sesion();
        vehiculosBeans = new VehiculosBeans();
        comerciosBeans = new ComerciosBeans();
        contribuyentesBeans = new ContribuyentesBeans();
        /*
         * Fondo
         */

         
         
         

         
         
        /*
         * fondo
         */

        java.util.Calendar ca = java.util.Calendar.getInstance();
        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());
        jXDatePickerFechaInicio.setDate(mydate);
        jXDatePickerFechaInicio.setFormats(new SimpleDateFormat("dd/MM/yyyy"));
        jXDatePickerFechaTerminacion.setDate(mydate);
        jXDatePickerFechaTerminacion.setFormats(new SimpleDateFormat("dd/MM/yyyy"));


        modelo = (DefaultTableModel) jTable1.getModel();

        modelo.isCellEditable(1, 1);

        TableColumn columnCheckBox = jTable1.getColumnModel().getColumn(0);
        columnCheckBox.setPreferredWidth(110);
        TableColumn columnId = jTable1.getColumnModel().getColumn(1);
        columnId.setPreferredWidth(280);
        TableColumn columnRegimen = jTable1.getColumnModel().getColumn(2);
        columnRegimen.setPreferredWidth(100);
        TableColumn columnIdRegimen = jTable1.getColumnModel().getColumn(4);
        columnIdRegimen.setPreferredWidth(200);
        ConsultarCodigoRecargo();
    }

    public List<String> getListaIdGrupo() {
        return ListaIdGrupo;
    }

    public void setListaIdGrupo(List<String> ListaIdGrupo) {
        this.ListaIdGrupo = ListaIdGrupo;
    }

    public List<String> getListaIdSubGrupo() {
        return ListaIdSubGrupo;
    }

    public void setListaIdSubGrupo(List<String> ListaIdSubGrupo) {
        this.ListaIdSubGrupo = ListaIdSubGrupo;
    }

    public List<Double> getListaTotalGrupo() {
        return ListaTotalGrupo;
    }

    public void setListaTotalGrupo(List<Double> ListaTotalGrupo) {
        this.ListaTotalGrupo = ListaTotalGrupo;
    }

    public List<Double> getListaTotalSubGrupo() {
        return ListaTotalSubGrupo;
    }

    public void setListaTotalSubGrupo(List<Double> ListaTotalSubGrupo) {
        this.ListaTotalSubGrupo = ListaTotalSubGrupo;
    }

    public int getNumeroRegistrosGrupo() {
        return NumeroRegistrosGrupo;
    }

    public void setNumeroRegistrosGrupo(int NumeroRegistrosGrupo) {
        this.NumeroRegistrosGrupo = NumeroRegistrosGrupo;
    }

    public int getNumeroRegistrosSubGrupo() {
        return NumeroRegistrosSubGrupo;
    }

    public void setNumeroRegistrosSubGrupo(int NumeroRegistrosSubGrupo) {
        this.NumeroRegistrosSubGrupo = NumeroRegistrosSubGrupo;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButtonRegresar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jButtonProcesar = new javax.swing.JButton();
        jXDatePickerFechaInicio = new org.jdesktop.swingx.JXDatePicker();
        jXDatePickerFechaTerminacion = new org.jdesktop.swingx.JXDatePicker();
        jCheckBoxIncluirRecargo = new javax.swing.JCheckBox();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldTotal = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jButtonSubGrupo = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jButtonGrupo = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jButtonGeneral = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("INFORME INGRESOS GENERALES");

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Fecha", "Regimen", "Codigo", "Pago", "Recargo"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setOpaque(false);

        jLabel2.setText("Fecha Inicio");

        jLabel3.setText("Fecha Terminacion");

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jButtonProcesar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/tools.png"))); // NOI18N
        jButtonProcesar.setToolTipText("Procesar");
        jButtonProcesar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonProcesarActionPerformed(evt);
            }
        });

        jCheckBoxIncluirRecargo.setText("Incluir Recargo");
        jCheckBoxIncluirRecargo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxIncluirRecargoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBoxIncluirRecargo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jXDatePickerFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jXDatePickerFechaTerminacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jButtonProcesar, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jLabel2))
                .addContainerGap(115, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(26, 26, 26)
                        .addComponent(jLabel3))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jXDatePickerFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(14, 14, 14)
                        .addComponent(jXDatePickerFechaTerminacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonProcesar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(22, 22, 22)
                                .addComponent(jLabel1))
                            .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jCheckBoxIncluirRecargo)))
                .addGap(76, 76, 76))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel4.setText("Total");

        jTextFieldTotal.setEnabled(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addGap(38, 38, 38)
                .addComponent(jTextFieldTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                .addGap(27, 27, 27))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Sub Grupos"));

        jButtonSubGrupo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/print.jpeg"))); // NOI18N
        jButtonSubGrupo.setToolTipText("Ingresos por Subgrupo");
        jButtonSubGrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSubGrupoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jButtonSubGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(38, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jButtonSubGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(6, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Grupos"));

        jButtonGrupo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/print.jpeg"))); // NOI18N
        jButtonGrupo.setToolTipText("Ingresos por Grupo");
        jButtonGrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGrupoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jButtonGrupo, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jButtonGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Generales"));

        jButtonGeneral.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/print.jpeg"))); // NOI18N
        jButtonGeneral.setToolTipText("Imprimir");
        jButtonGeneral.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGeneralActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonGeneral, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                .addGap(25, 25, 25))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jButtonGeneral, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 641, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(197, 197, 197)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(94, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, 0, 80, Short.MAX_VALUE)
                        .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(53, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonProcesarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonProcesarActionPerformed

    Procesar();
}//GEN-LAST:event_jButtonProcesarActionPerformed

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed

    dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

private void jButtonGeneralActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGeneralActionPerformed
    // TODO add your handling code here:
    try {
        String STotal = jTextFieldTotal.getText();
        if (STotal == null || STotal.equals("") || STotal.equals("0.0")) {
            JOptionPane.showMessageDialog(this, "No existen recibos en las fechas indicadas", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String reportSource;
        String reportDest;
        String sql;

        // reportSource = sesion.getRutaReportes() + "ContabilidadInformeIngresos.jrxml";
        reportSource = sesion.getRutaReportes() + "ContabilidadInformeIngresosGeneral.jrxml";

        //reportDest = sesion.getRutaDestino() + "ContabilidadInformeIngresos.html";
        Map<String, Object> params = new HashMap<String, Object>();


        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_MUNICIPIO", sesion.getMunicipio());
        params.put("P_NOMBREUSUARIO", sesion.getUsuario());
        params.put("P_USERNAME", sesion.getUsername());
        String ltitulo ="INFORME DE INGRESOS GENERAL";
        params.put("P_TITULO",ltitulo);
        java.util.Date FechaDate = jXDatePickerFechaInicio.getDate();
        java.sql.Date FechaInicio = new java.sql.Date(FechaDate.getTime());
        if (FechaInicio == null) {
            JOptionPane.showMessageDialog(this, "Ingrese la fecha de inicio", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jXDatePickerFechaInicio.requestFocus();
            return;
        }
        FechaDate = jXDatePickerFechaTerminacion.getDate();
        java.sql.Date FechaTerminacion = new java.sql.Date(FechaDate.getTime());
        if (FechaTerminacion == null) {
            JOptionPane.showMessageDialog(this, "Ingrese la fecha de terminacion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jXDatePickerFechaTerminacion.requestFocus();
            return;
        }
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        String inicio = formatter.format(FechaInicio);
        String terminacion = formatter.format(FechaTerminacion);
        String condicion;
        if (jCheckBoxIncluirRecargo.isSelected()) {
            condicion = "Desde: (" + inicio + ") Hasta: (" + terminacion + ") Incluye recargos";
        } else {
            condicion = "Desde: (" + inicio + ") Hasta: (" + terminacion + ") no incluye recargos";
        }

        params.put("P_CONDICION", condicion);
        String Stotal = jTextFieldTotal.getText();
        Double total = Double.parseDouble(Stotal);
        params.put("P_TOTALPAGADO", total);


        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);
        JasperViewer.viewReport(jasperPrint, false);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonGeneralActionPerformed

private void jCheckBoxIncluirRecargoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxIncluirRecargoActionPerformed
    // TODO add your handling code here:
    Procesar();
}//GEN-LAST:event_jCheckBoxIncluirRecargoActionPerformed

private void jButtonSubGrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSubGrupoActionPerformed
    // TODO add your handling code here:
    try {
        String STotal = jTextFieldTotal.getText();
        if (STotal == null || STotal.equals("") || STotal.equals("0.0")) {
            JOptionPane.showMessageDialog(this, "No existen recibos en las fechas indicadas", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String reportSource;
        String reportDest;
        String sql;

        // reportSource = sesion.getRutaReportes() + "ContabilidadInformeIngresos.jrxml";
        reportSource = sesion.getRutaReportes() + "ContabilidadInformeIngresosGeneralSubGrupo.jrxml";

        //reportDest = sesion.getRutaDestino() + "ContabilidadInformeIngresos.html";
        Map<String, Object> params = new HashMap<String, Object>();


        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_MUNICIPIO", sesion.getMunicipio());
        params.put("P_NOMBREUSUARIO", sesion.getUsuario());
        params.put("P_USERNAME", sesion.getUsername());
        String ltitulo ="INFORME DE INGRESOS GENERAL POR SUBGRUPO";
        params.put("P_TITULO",ltitulo);
        java.util.Date FechaDate = jXDatePickerFechaInicio.getDate();
        java.sql.Date FechaInicio = new java.sql.Date(FechaDate.getTime());
        if (FechaInicio == null) {
            JOptionPane.showMessageDialog(this, "Ingrese la fecha de inicio", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jXDatePickerFechaInicio.requestFocus();
            return;
        }
        FechaDate = jXDatePickerFechaTerminacion.getDate();
        java.sql.Date FechaTerminacion = new java.sql.Date(FechaDate.getTime());
        if (FechaTerminacion == null) {
            JOptionPane.showMessageDialog(this, "Ingrese la fecha de terminacion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jXDatePickerFechaTerminacion.requestFocus();
            return;
        }
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        String inicio = formatter.format(FechaInicio);
        String terminacion = formatter.format(FechaTerminacion);
        String condicion;
        if (jCheckBoxIncluirRecargo.isSelected()) {
            condicion = "Por Subgrupo Desde: (" + inicio + ") Hasta: (" + terminacion + ") Incluye recargos";
        } else {
            condicion = "Por Subgrupo Desde: (" + inicio + ") Hasta: (" + terminacion + ") no incluye recargos";
        }

        params.put("P_CONDICION", condicion);
        String Stotal = jTextFieldTotal.getText();
        Double total = Double.parseDouble(Stotal);
        params.put("P_TOTALPAGADO", total);


        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);
        JasperViewer.viewReport(jasperPrint, false);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonSubGrupoActionPerformed

private void jButtonGrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGrupoActionPerformed
    // TODO add your handling code here:
    try {
        String STotal = jTextFieldTotal.getText();
        if (STotal == null || STotal.equals("") || STotal.equals("0.0")) {
            JOptionPane.showMessageDialog(this, "No existen recibos en las fechas indicadas", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String reportSource;
        String reportDest;
        String sql;

        // reportSource = sesion.getRutaReportes() + "ContabilidadInformeIngresos.jrxml";
        reportSource = sesion.getRutaReportes() + "ContabilidadInformeIngresosGeneralGrupo.jrxml";

        //reportDest = sesion.getRutaDestino() + "ContabilidadInformeIngresos.html";
        Map<String, Object> params = new HashMap<String, Object>();


        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_MUNICIPIO", sesion.getMunicipio());
        params.put("P_NOMBREUSUARIO", sesion.getUsuario());
        params.put("P_USERNAME", sesion.getUsername());
        String ltitulo ="INFORME DE INGRESOS GENERAL POR GRUPO";
        params.put("P_TITULO",ltitulo);
        java.util.Date FechaDate = jXDatePickerFechaInicio.getDate();
        java.sql.Date FechaInicio = new java.sql.Date(FechaDate.getTime());
        if (FechaInicio == null) {
            JOptionPane.showMessageDialog(this, "Ingrese la fecha de inicio", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jXDatePickerFechaInicio.requestFocus();
            return;
        }
        FechaDate = jXDatePickerFechaTerminacion.getDate();
        java.sql.Date FechaTerminacion = new java.sql.Date(FechaDate.getTime());
        if (FechaTerminacion == null) {
            JOptionPane.showMessageDialog(this, "Ingrese la fecha de terminacion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jXDatePickerFechaTerminacion.requestFocus();
            return;
        }
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        String inicio = formatter.format(FechaInicio);
        String terminacion = formatter.format(FechaTerminacion);
        String condicion;
        if (jCheckBoxIncluirRecargo.isSelected()) {
            condicion = "Por Grupo Desde: (" + inicio + ") Hasta: (" + terminacion + ") Incluye recargos";
        } else {
            condicion = "Por Grupo Desde: (" + inicio + ") Hasta: (" + terminacion + ") no incluye recargos";
        }

        params.put("P_CONDICION", condicion);
        String Stotal = jTextFieldTotal.getText();
        Double total = Double.parseDouble(Stotal);
        params.put("P_TOTALPAGADO", total);


        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);
        JasperViewer.viewReport(jasperPrint, false);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonGrupoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ContabilidadInformeIngresoGeneralesFrame().setVisible(true);
            }
        });
    }

    private void Procesar() {
        try {
            sesion.LimpiarTemporales();
            boolean control = false;
            while (control == false) {
                int n = jTable1.getRowCount();
                if (n <= 0) {
                    control = true;
                } else {
                    modelo.removeRow(0);
                }

            }//while

            CargarRecibos();

            CalcularRegistrosTotal();


            String sql = " select *, "
                    + "totalregimen from recibescontabilidadtemporalinformes where idmunicipio='" + sesion.getIdmunicipio() + "' and username='" + sesion.getUsername() + "' group by  idregimen";

            CargarTodosRegistros(sql);
            CalcularTotalPagado();



        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Procesar()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void CargarRecibos() {
        try {
//cargar los contribuyentes
           
            String lcondicionrecargo = "";
            if (jCheckBoxIncluirRecargo.isSelected()) {
                //cuando incluimos el recargo debemos validar por no o si
                //para que no queden por fuera los que no tienen
                lcondicionrecargo = "and (recibesdetalles.esrecargo='no' or recibesdetalles.esrecargo='si')";
            } else {
                //excluimos los que tienen recargos
                lcondicionrecargo = " and (recibesdetalles.esrecargo='no')";
            }

            String sql = "select recibesdetalles.pago, recibesdetalles.idregimen,"
                    + " recibes.fecha, regimen.regimen, "

                    + " recibesdetalles.esrecargo, subgruporegimen.idsubgruporegimen,"
                    + " subgruporegimen.subgrupo , gruporegimen.grupo,gruporegimen.idgruporegimen "
                    + " from recibes, recibesdetalles, subgruporegimen, regimen, gruporegimen"
                    + " where recibes.idmunicipio =? "
                    + " and recibes.anulado = 'no' "
                    + " and recibes.fecha >= ? "
                    + " and recibes.fecha <= ? "
                    + lcondicionrecargo
                    + " and recibesdetalles.idmunicipio = recibes.idmunicipio "
                    + " and recibes.idrecibo = recibesdetalles.idrecibo"
                    + " and regimen.idmunicipio=?"
                    + " and regimen.idregimen= recibesdetalles.idregimen"
                    + " and subgruporegimen.idmunicipio=?"
                    + " and subgruporegimen.idsubgruporegimen = regimen.idsubgruporegimen"
                    + " and gruporegimen.idmunicipio =recibes.idmunicipio"
                    + " and gruporegimen.activo='si' "
                    + " and subgruporegimen.idgruporegimen = gruporegimen.idgruporegimen ";
            CargarTemporalesRecibos(sql);


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    
    private void CargarTemporalesRecibos(String sql) {
        try {
       
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            java.util.Date FechaDate = jXDatePickerFechaInicio.getDate();
            java.sql.Date FechaInicio = new java.sql.Date(FechaDate.getTime());
            if (FechaInicio == null) {
                JOptionPane.showMessageDialog(this, "Ingrese la fecha de inicio", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jXDatePickerFechaInicio.requestFocus();
                return;
            }
            FechaDate = jXDatePickerFechaTerminacion.getDate();
            java.sql.Date FechaTerminacion = new java.sql.Date(FechaDate.getTime());
            if (FechaTerminacion == null) {
                JOptionPane.showMessageDialog(this, "Ingrese la fecha de terminacion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jXDatePickerFechaTerminacion.requestFocus();
                return;
            }

            PreparedStatement psquery = sesion.con.prepareStatement(sql);
            psquery.setString(1, sesion.getIdmunicipio());

            psquery.setDate(2, FechaInicio); //fecha inscripion

            psquery.setDate(3, FechaTerminacion); //fecha inscripion
            psquery.setString(4, sesion.getIdmunicipio());
            psquery.setString(5, sesion.getIdmunicipio());

            ResultSet rs = psquery.executeQuery();

// Bucle para cada resultado en la consulta
            while (rs.next()) {
                java.util.Date myFechaDatos = rs.getDate("fecha");
                String regimen = rs.getString("regimen");
                String idRegimen = rs.getString("idregimen");
                String propietario = "";
                String subgrupo = rs.getString("subgrupo");
                String idSubGrupoRegimen = rs.getString("idsubgruporegimen");
                String grupo = rs.getString("grupo");
                String idGrupoRegimen = rs.getString("idgruporegimen");
                Double pago = rs.getDouble("pago");

                String esrecargo = rs.getString("esrecargo");

                esrecargo = esrecargo.toLowerCase();
                if (esrecargo.equals("si")) {
                    //idSubGrupoRegimen = sesion.getIdRegimenRecargo();
                    //buscar el subgrupo Codigo de Recargo
                }
                String sqlInsert = "insert into recibescontabilidadtemporal "
                        + "(idrecibo ,idmunicipio ,fecha,idregimen ,idsubgruporegimen ,idgruporegimen,"
                        + " propietario,valor,cantidad,pago,esrecargo,"
                        + "saldo,regimen,subgrupo,grupo,idcorregimiento, corregimiento,id,tipoid, username)"
                        + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                PreparedStatement prestInsert = sesion.con.prepareStatement(sqlInsert);
//idrecibo, idmunicipio, fecha, idregimen, propietario, valor, cantidad, pago, esrecargo, saldo, username
                prestInsert.setInt(1, 0);
                prestInsert.setString(2, sesion.getIdmunicipio());


                java.sql.Date date = new java.sql.Date(myFechaDatos.getTime());
                prestInsert.setDate(3, date);

                prestInsert.setString(4, idRegimen); //idregimen
                prestInsert.setString(5, idSubGrupoRegimen); //idsubgruporegimen
                prestInsert.setString(6, idGrupoRegimen); //idgrupo
                prestInsert.setString(7, propietario);
                prestInsert.setDouble(8, 0.0);//valor
                prestInsert.setInt(9, 0);//cantidad
                prestInsert.setDouble(10, pago);
                prestInsert.setString(11, esrecargo);
                prestInsert.setDouble(12, 0.0);//saldo
                prestInsert.setString(13, regimen);
                prestInsert.setString(14, subgrupo);
                prestInsert.setString(15, grupo);
                prestInsert.setString(16, "");
                prestInsert.setString(17, "");
                prestInsert.setString(18, "");
                prestInsert.setString(19, "");
                prestInsert.setString(20, sesion.getUsername());
                prestInsert.executeUpdate();
                //   sesion.con.close();

            }
            //aris
            sesion.con.close();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "CargarTemporalesRecibos()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }

    }

    private void CalcularRegistrosTotal() {
        try {
            String sql = "select *, sum(pago) as total from recibescontabilidadtemporal where idmunicipio='" + sesion.getIdmunicipio() + "' and username='" + sesion.getUsername() + "' group by  idregimen";
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }


            PreparedStatement psquery = sesion.con.prepareStatement(sql);


            ResultSet rs = psquery.executeQuery();
            Double lgrantotal = 0.0;
// Bucle para cada resultado en la consulta
            while (rs.next()) {
                java.util.Date myFechaDatos = rs.getDate("fecha");
                String regimen = rs.getString("regimen");
                String idRegimen = rs.getString("idregimen");

                String propietario = "";
                String subgrupo = rs.getString("subgrupo");
                String idSubGrupoRegimen = rs.getString("idsubgruporegimen");
                String grupo = rs.getString("grupo");
                String idGrupoRegimen = rs.getString("idgruporegimen");
                Double pago = rs.getDouble("pago");
                Double ltotal = rs.getDouble("total");

                lgrantotal += ltotal;
                String esrecargo = rs.getString("esrecargo");

                esrecargo = esrecargo.toLowerCase();
                if (esrecargo.equals("si")) {
                    //idSubGrupoRegimen = sesion.getIdRegimenRecargo();
                    //buscar el subgrupo Codigo de Recargo
                }
                String sqlInsert = "insert into recibescontabilidadtemporalinformes "
                        + "(idrecibo ,idmunicipio ,fecha,idregimen ,idsubgruporegimen ,idgruporegimen,"
                        + " propietario,valor,cantidad,pago,esrecargo,"
                        + "saldo,regimen,subgrupo,grupo,totalregimen,totalsubgrupo,totalgrupo,grantotal,idcorregimiento, corregimiento,id,tipoid,username)"
                        + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                PreparedStatement prestInsert = sesion.con.prepareStatement(sqlInsert);
//idrecibo, idmunicipio, fecha, idregimen, propietario, valor, cantidad, pago, esrecargo, saldo, username
                prestInsert.setInt(1, 0);
                prestInsert.setString(2, sesion.getIdmunicipio());


                java.sql.Date date = new java.sql.Date(myFechaDatos.getTime());
                prestInsert.setDate(3, date);

                prestInsert.setString(4, idRegimen); //idregimen
                prestInsert.setString(5, idSubGrupoRegimen); //idsubgruporegimen
                prestInsert.setString(6, idGrupoRegimen); //idgrupo
                prestInsert.setString(7, propietario);
                prestInsert.setDouble(8, 0.0);//valor
                prestInsert.setInt(9, 0);//cantidad
                prestInsert.setDouble(10, pago);
                prestInsert.setString(11, esrecargo);
                prestInsert.setDouble(12, 0.0);//saldo
                prestInsert.setString(13, regimen);
                prestInsert.setString(14, subgrupo);
                prestInsert.setString(15, grupo);
                prestInsert.setDouble(16, ltotal);//totalregimen
                prestInsert.setDouble(17, 0.0);//totalsubgrupo
                prestInsert.setDouble(18, 0.0);//totalgrupo
                prestInsert.setDouble(19, lgrantotal);//totalgrupo               
                prestInsert.setString(20, "");
                prestInsert.setString(21, "");
                prestInsert.setString(22, "");
                 prestInsert.setString(23, "");
                                prestInsert.setString(24, sesion.getUsername());

                prestInsert.executeUpdate();
                //   sesion.con.close();

            }
            //actualizo el gran total
            String sqlupdate = "update recibescontabilidadtemporalinformes set grantotal='" + lgrantotal + "' where idmunicipio='" + sesion.getIdmunicipio() + "' and username='" + sesion.getUsername() + "'";
            PreparedStatement presUpdate = sesion.con.prepareStatement(sqlupdate);
            presUpdate.executeUpdate();
            sql = "select sum(totalregimen) as total, idsubgruporegimen from recibescontabilidadtemporalinformes"
                    + "  where idmunicipio='" + sesion.getIdmunicipio() + "' and username='" + sesion.getUsername() + "'"
                    + " group by idsubgruporegimen";
            CargarListadoTotalesSubGrupos(sql);
            sql = "select sum(totalregimen) as total, idgruporegimen from recibescontabilidadtemporalinformes "
                    + "  where idmunicipio='" + sesion.getIdmunicipio() + "' and username='" + sesion.getUsername() + "'"
                    + " group by idgruporegimen";
            CargarListadoTotalesGrupos(sql);
            //aris

            if (getNumeroRegistrosSubGrupo() != - 1) {
                ActualizarTotalesSubGrupo();
            }
            if (getNumeroRegistrosGrupo() != - 1) {
                ActualizarTotalesGrupo();
            }


            sesion.con.close();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "CalcularRegistrosTotal()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }

    }

    private void CargarTodosRegistros(String sql) {
        try {

            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            PreparedStatement psquery = sesion.con.prepareStatement(sql);
            ResultSet rs = psquery.executeQuery();

// Bucle para cada resultado en la consulta
            while (rs.next()) {
                // Se crea un array que será una de las filas de la tabla.
                Object[] fila = new Object[5]; // Hay tres columnas en la tabla


                Format formatter;
                formatter = new SimpleDateFormat("dd/MM/yyyy");
                Date fecha = rs.getDate("fecha");
                String MyFecha = formatter.format(fecha);

                fila[0] = MyFecha;
                fila[1] = rs.getString("regimen");
                fila[2] = rs.getString("idregimen");
                fila[3] = rs.getDouble("totalregimen");
                String esrecargo = rs.getString("esrecargo");
                esrecargo = esrecargo.toLowerCase();
                if (esrecargo.equals("si")) {
                    fila[4] = new Boolean(true);
                } else {
                    fila[4] = new Boolean(false);
                }


                modelo.addRow(fila);


            }
            sesion.con.close();
            this.jTable1.setModel(modelo);
            jTable1.setVisible(true);
            //aris++
            this.jTable1.addMouseListener(new MouseAdapter() {

                public void mouseClicked(MouseEvent e) {

                    fila = jTable1.rowAtPoint(e.getPoint());
                    int columna = jTable1.columnAtPoint(e.getPoint());
                    if ((fila > -1) && (columna > -1)) {
//                        jTextFieldIdRecibo.setText(String.valueOf(jTable1.getValueAt(fila, 2)));
                    }
                }
            });


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "CargarTodosRegistros()\nError " + ex.getMessage(), "Error...CargarTodosRegistros()", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void CalcularTotalPagado() {
        try {
            Double valor = 0.0;
            Double TotalPagado = 0.0;
            int n = jTable1.getRowCount();
            for (int i = 0; i < n; i++) {

                String SValor = String.valueOf(jTable1.getValueAt(i, 3));
                if (SValor.equals("")) {
                    valor = 0.0;
                } else {
                    valor = Double.parseDouble(SValor);
                    TotalPagado += valor;
                }
            }
            jTextFieldTotal.setText(sesion.getFormateador().format(TotalPagado));
        } catch (Exception ex) {
            String tabString = "Modulo: CalcularTotalPagado() \n " + ex.getMessage().toString();
            JTextArea textArea = new JTextArea(tabString, 2, 20);
            textArea.setEditable(false);
            JOptionPane.showMessageDialog(null, textArea, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    public void ConsultarCodigoRecargo() {

        try {

            CodigosRecargoBeans codigosRecargoBeans = new CodigosRecargoBeans();
            if (codigosRecargoBeans.Consultar()) {
                String IdRegimenRecargo = codigosRecargoBeans.getIdRegimenRecargo();
                //  jTextFieldIdCodigoRecargo.setText(IdRegimenRecargo);
                repaint();
            } else {
                sesion.MostrarMensajeAdvertencia("Mensaje", "No existen codigos de recargos");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }

    }

    public boolean CargarListadoTotalesSubGrupos(String sql) {
        try {
            NumeroRegistrosSubGrupo = -1;
            ListaIdSubGrupo.removeAll(ListaIdSubGrupo);
            ListaTotalSubGrupo.removeAll(ListaTotalSubGrupo);

            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(null, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }

            String sqlquery = sql;
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();
            if (x == 0) {
              
                sesion.con.close();
                return false;
            }

            ListaIdSubGrupo.add(rs.getString("idsubgruporegimen"));
            ListaTotalSubGrupo.add(rs.getDouble("total"));

            NumeroRegistrosSubGrupo++;

            while (rs.next()) {
                ListaIdSubGrupo.add(rs.getString("idsubgruporegimen"));
                ListaTotalSubGrupo.add(rs.getDouble("total"));

                NumeroRegistrosSubGrupo++;

            }


            sesion.con.close();
            return true;
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "CargarListadoTotalesSubGrupos()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);

        }

        return false;
    }

    public boolean CargarListadoTotalesGrupos(String sql) {
        try {
           
            NumeroRegistrosGrupo = -1;
            ListaIdGrupo.removeAll(ListaIdGrupo);
            ListaTotalGrupo.removeAll(ListaTotalGrupo);

            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(null, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }

            String sqlquery = sql;
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();
            if (x == 0) {

                sesion.con.close();
                return false;
            }

            ListaIdGrupo.add(rs.getString("idgruporegimen"));
            ListaTotalGrupo.add(rs.getDouble("total"));

            NumeroRegistrosGrupo++;

            while (rs.next()) {
                ListaIdGrupo.add(rs.getString("idgruporegimen"));
                ListaTotalGrupo.add(rs.getDouble("total"));

                NumeroRegistrosGrupo++;

            }


            sesion.con.close();
            return true;
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "CargarListadoTotalesGrupos()\nError " + ex.getMessage(), "Error.", JOptionPane.ERROR_MESSAGE);

        }

        return false;
    }

    private void ActualizarTotalesSubGrupo() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(null, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String lidsubgrupo;
            Double ltotal;
            String sqlupdate;
            PreparedStatement presUpdate;
            for (int i = 0; i <= getNumeroRegistrosSubGrupo(); i++) {
                lidsubgrupo = getListaIdSubGrupo().get(i);
                ltotal = getListaTotalSubGrupo().get(i);
                sqlupdate = "update recibescontabilidadtemporalinformes "
                        + " set totalsubgrupo='" + ltotal + "' "
                        + " where idmunicipio='" + sesion.getIdmunicipio() + "' and username='" + sesion.getUsername() + "'"
                        + " and idsubgruporegimen ='"+lidsubgrupo+"'";
                
                presUpdate = sesion.con.prepareStatement(sqlupdate);
                presUpdate.executeUpdate();
            }
            sesion.con.close();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "ActualizarTotalesSubGrupo()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);

        }
    }

     private void ActualizarTotalesGrupo() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(null, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String lidgrupo;
            Double ltotal;
            String sqlupdate;
            PreparedStatement presUpdate;
            for (int i = 0; i <= getNumeroRegistrosGrupo(); i++) {
                lidgrupo = getListaIdGrupo().get(i);
                ltotal = getListaTotalGrupo().get(i);
                sqlupdate = "update recibescontabilidadtemporalinformes "
                        + " set totalgrupo='" + ltotal + "' "
                        + " where idmunicipio='" + sesion.getIdmunicipio() + "' and username='" + sesion.getUsername() + "'"
                        + " and idgruporegimen ='"+lidgrupo+"'";
                      
                presUpdate = sesion.con.prepareStatement(sqlupdate);
                presUpdate.executeUpdate();
            }
            sesion.con.close();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "ActualizarTotalesSubGrupo()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);

        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButtonGeneral;
    private javax.swing.JButton jButtonGrupo;
    private javax.swing.JButton jButtonProcesar;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JButton jButtonSubGrupo;
    private javax.swing.JCheckBox jCheckBoxIncluirRecargo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextFieldTotal;
    private org.jdesktop.swingx.JXDatePicker jXDatePickerFechaInicio;
    private org.jdesktop.swingx.JXDatePicker jXDatePickerFechaTerminacion;
    // End of variables declaration//GEN-END:variables
}
